﻿// Decompiled with JetBrains decompiler
// Type: 我的小工具.SoftDog
// Assembly: 开发辅助工具, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null
// MVID: F78E5980-5E94-4E46-ABDF-DC8C6CBF52AA
// Assembly location: K:\Tools\工具\开发辅助工具庆六一版\开发辅助工具2015-06-01\开发辅助工具.exe

using Microsoft.VisualBasic;
using System;
using System.Text;

namespace 我的小工具
{
  internal class SoftDog
  {
    public static bool IsUseable = false;

    public static int GetCount()
    {
      Dog dog = new Dog();
      dog.DogAddr = 0;
      dog.DogBytes = 123;
      dog.Read_Dog(dog.DogCascade, dog.DogPassword, dog.DogAddr, dog.DogBytes, dog.DogData, ref dog.RetCode);
      if (dog.RetCode != 0)
      {
        dog.DogPassword = 0;
        dog.Read_Dog(dog.DogCascade, dog.DogPassword, dog.DogAddr, dog.DogBytes, dog.DogData, ref dog.RetCode);
        if (dog.RetCode != 0)
          throw new Exception("未检测到软件狗");
      }
      return Convert.ToInt32(dog.DogData[113]);
    }

    public static void WriteDog()
    {
      Dog dog = new Dog();
      dog.DogAddr = 0;
      dog.DogBytes = 123;
      dog.Read_Dog(dog.DogCascade, dog.DogPassword, dog.DogAddr, dog.DogBytes, dog.DogData, ref dog.RetCode);
      if (dog.RetCode != 0)
      {
        dog.DogPassword = 0;
        dog.Read_Dog(dog.DogCascade, dog.DogPassword, dog.DogAddr, dog.DogBytes, dog.DogData, ref dog.RetCode);
        if (dog.RetCode != 0)
          throw new Exception("未检测到软件狗");
      }
      dog.DogAddr = 113;
      dog.DogBytes = 1;
      dog.DogData[0] = (byte) 254;
      dog.Write_Dog(dog.DogCascade, dog.DogPassword, dog.DogAddr, dog.DogBytes, dog.DogData, ref dog.RetCode);
    }

    public static void ReWriteDog()
    {
      Dog dog = new Dog();
      dog.DogAddr = 0;
      dog.DogBytes = 123;
      dog.Read_Dog(dog.DogCascade, dog.DogPassword, dog.DogAddr, dog.DogBytes, dog.DogData, ref dog.RetCode);
      if (dog.RetCode != 0)
      {
        dog.DogPassword = 0;
        dog.Read_Dog(dog.DogCascade, dog.DogPassword, dog.DogAddr, dog.DogBytes, dog.DogData, ref dog.RetCode);
        if (dog.RetCode != 0)
          throw new Exception("未检测到软件狗");
      }
      dog.DogAddr = 0;
      dog.DogBytes = 79;
      string str = "mysoftsldotnetslxm40zsxm40slqy40zsqy40sljt40zsjt40hyxt30kfxt30cbqy26cbqy30cbjt3";
      int index = 0;
      foreach (char @char in str.ToCharArray())
      {
        int num = Strings.AscW(@char);
        dog.DogData[index] = (byte) num;
        ++index;
      }
      dog.Write_Dog(dog.DogCascade, dog.DogPassword, dog.DogAddr, dog.DogBytes, dog.DogData, ref dog.RetCode);
    }

    private static string ReadDog(int iDogAddr, int iDogBytes)
    {
      Dog dog = new Dog();
      dog.DogAddr = 0;
      dog.DogBytes = 123;
      dog.Read_Dog(dog.DogCascade, dog.DogPassword, dog.DogAddr, dog.DogBytes, dog.DogData, ref dog.RetCode);
      if (dog.RetCode != 0)
      {
        dog.DogPassword = 0;
        dog.Read_Dog(dog.DogCascade, dog.DogPassword, dog.DogAddr, dog.DogBytes, dog.DogData, ref dog.RetCode);
        if (dog.RetCode != 0)
          throw new Exception("未检测到软件狗");
      }
      StringBuilder stringBuilder = new StringBuilder();
      for (int index = iDogAddr; index <= iDogAddr + iDogBytes - 1; ++index)
      {
        int CharCode = (int) dog.DogData[index];
        stringBuilder.Append(CharCode == 0 ? "" : Strings.ChrW(CharCode).ToString());
      }
      return stringBuilder.ToString();
    }

    public static void Init()
    {
      try
      {
        SoftDog.GetCount();
        SoftDog.IsUseable = true;
      }
      catch
      {
        SoftDog.IsUseable = false;
      }
    }

    public static bool getIsZydog()
    {
      return Strings.InStr(Strings.LCase(SoftDog.ReadDog(0, 79)), "dotnet", CompareMethod.Binary) > 0;
    }
  }
}
